<?php
$database = parse_ini_file('./.env');
$mysql = new PDO("mysql:host={$database['DB_HOST']};dbname={$database['DB_NAME']};charset={$database['DB_CHARSET']}", $database['DB_USER'], $database['DB_PASS']);
$username = $argv[1] ?? '';
$password = $argv[2]?? '';
if(!$username){
    exit("请输入用户名\n使用方法：php resetadmin.php username password\n");
}
if(!$password){
    exit("请输入密码\n使用方法：php resetadmin.php username password\n");
}
$salt = mt_rand(100000, 999999);
$sql = "UPDATE `admin` SET `password` = :password, salt = :salt, error_num = 0, `status` = 1 WHERE `username` = :username";
$stmt = $mysql->prepare($sql);
$stmt->execute([':password' => md5($password.$salt), ':salt' => $salt, ':username' => $username]);
echo "执行成功\n";